{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 变量与数据类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 变量：相比于数学中的变量，在计算机程序中，变量不仅可以是数字，还可以是任意数据类型。变量在程序中用一个变量名表示，Python中变量的命名需要遵循一定的语法规则。\n",
    "变量名必须是英文[大小写皆可]、数字和下划线的组合，并且不能以数字开头。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "以下是合法的变量名:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "a=1\n",
    "A=2\n",
    "_tt=12\n",
    "hello=123\n",
    "hEllO=2324\n",
    "a1_B2=1212312\n",
    "_=111111"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "以下是非法的变量名："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "1a=12\n",
    "12=111\n",
    "1_=323"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 数据类型：Python同任何其他语言一样，也包含基本的数据类型，包括：整数、浮点数、字符串、布尔值、空值、常量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 整数\n",
    "a=1\n",
    "b=2\n",
    "\n",
    "# 浮点数\n",
    "c=1.0\n",
    "d=0.11111\n",
    "\n",
    "# 字符串\n",
    "s1='HELLO WORLD'\n",
    "s2=\"欢迎来到Python的基础课！\"\n",
    "s3='''我也是合法的字符串呢'''\n",
    "s4='我是字符串'\\\n",
    "'并且我还可以换行写'\n",
    "s5='这个是默认拼接' '非常有意思的写法！'\n",
    "\n",
    "# 布尔值\n",
    "f1=True\n",
    "f2=False\n",
    "\n",
    "# 空值\n",
    "t=None\n",
    "\n",
    "# 常量：指的是不能变的变量，比如常用的数学常数π就是一个常量。在Python中，通常用全部大写的变量名表示常量：\n",
    "PI=3.14159"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 判断一个变量的数据类型\n",
    "type(f1)\n",
    "type(PI)\n",
    "type(s5)\n",
    "isinstance(f1,float)\n",
    "isinstance(f1,bool)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 表达式、运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
